from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager
from flask_mail import Mail
from flask_wtf.csrf import CSRFProtect

# 初始化扩展
db = SQLAlchemy()
login_manager = LoginManager()
mail = Mail()
csrf = CSRFProtect()

@login_manager.user_loader
def load_user(user_id):
    """加载用户"""
    from .models import User
    return User.query.get(int(user_id))

def init_extensions(app):
    """初始化所有扩展"""
    db.init_app(app)
    login_manager.init_app(app)
    mail.init_app(app)
    csrf.init_app(app)
    
    # 配置登录管理器
    login_manager.login_view = 'auth_zyy.login_zyy'
    login_manager.login_message = '请先登录'
    login_manager.login_message_category = 'info' 